package com.liusha.quicksand.interceptor;//package com.liusha.quicksand.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 一世长安一世欢
 * @Date: 2020/10/27
 * @Time: 1:02
 * @Description: No Description
 */

@Configuration
public class LoginConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 注册拦截器
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        InterceptorRegistration loginRegistry = registry.addInterceptor(loginInterceptor);

        // 拦截路径
        loginRegistry.addPathPatterns("/**");
        loginRegistry.addPathPatterns("/post");

        // 排除路径
        loginRegistry.excludePathPatterns("/index");
        loginRegistry.excludePathPatterns("/login");
        loginRegistry.excludePathPatterns("/search");
        loginRegistry.excludePathPatterns("/logout");
        loginRegistry.excludePathPatterns("/registered");
        loginRegistry.excludePathPatterns("/saveuser");
        loginRegistry.excludePathPatterns("/comments");
        loginRegistry.excludePathPatterns("/blog/{blogId}");
        loginRegistry.excludePathPatterns("/comments/{blogId}");
        loginRegistry.excludePathPatterns("/admin/**");
        loginRegistry.excludePathPatterns("/admin/loginAdmin");

        // 排除资源请求
        loginRegistry.excludePathPatterns("/css/*.css");
        loginRegistry.excludePathPatterns("/js/*.js");
        loginRegistry.excludePathPatterns("/fonts/*.eot");
        loginRegistry.excludePathPatterns("/fonts/*.svg");
        loginRegistry.excludePathPatterns("/fonts/*.ttf");
        loginRegistry.excludePathPatterns("/fonts/*.woff");
        loginRegistry.excludePathPatterns("/fonts/*.woff2");
        loginRegistry.excludePathPatterns("/lib/qrcode/*.js");
        loginRegistry.excludePathPatterns("/images/*.png");
        loginRegistry.excludePathPatterns("/images/*.jpg");
        loginRegistry.excludePathPatterns("/images/*.jpeg");
        loginRegistry.excludePathPatterns("/^(http)[s]*(\\:\\/\\/)/,'https://images.weserv.nl/?url='");
//        loginRegistry.excludePathPatterns("pager");
    }
}
